<!-- ***************************************************************************
* Copyright (c) 2015 IBM Corp.
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*    http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**************************************************************************** -->
<!-- this sourcecode is modified by Huawei Technologies Co., Ltd. -->
<!DOCTYPE HTML>
<html>

<head>
  <title>Huawei Air - Config</title>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <link rel="stylesheet" href="css/themes/claro/claro.css">
  <link rel="stylesheet" href="css/themes/dijit.css">
  
  <script type="text/javascript" src="js/air-common.js"></script>
  <script src="https://download.dojotoolkit.org/release-1.7.12/dojo-release-1.7.12/dojo/dojo.js" djConfig="parseOnLoad: true"></script>

  <script>
    dojo.require("dojo.parser");
	dojo.require("dojox.grid.DataGrid");
	dojo.require("dojo.data.ItemFileWriteStore");    
    dojo.require("dijit.form.Button");
    dojo.require("dijit.Dialog");
    dojo.require("dijit.form.TextBox");
    dojo.require("dijit.Toolbar");
    dojo.require("dijit.Declaration");
    
    dojo.require("dojo.cookie");
    
    dojo.addOnLoad(pageLoaded);
    
    function pageLoaded() {
    	updateLoggedInUserWelcome();
    	//createAndStartGrid();
    }
    
    var basePath =  "rest/info/";
    var customersPath = "customers/"
    var bookingsPath = "bookings/"
    
    function getDataServiceInformation() {
    	var grid, store, dataStore;
    	
    	dojo.xhrGet({
			url: bookingsPath.concat(basePath.concat("config/dataServices")),
			handleAs: "json",
			load: function(response, ioArgs) {
				var theData = { items : response };
				var tableData = '';
			 
					tableData += '<table border="1">';
					tableData += '<tr>';
					tableData += '   <th>JNDI key</th>';
					tableData += '   <th>Description</th>';		
					tableData += '</tr>';
					var itemLength = theData.items.length;
				    for (var i = 0; i < itemLength; i++){
						tableData += '<tr>';
						tableData += '   <td>'+theData.items[i].name+'</td>';
						tableData += '   <td>'+theData.items[i].description+'</td>';		
						tableData += '</tr>';
				    }
					tableData += '</table>';
				
    			document.getElementById('targetLoc').innerHTML=tableData;
				return false;				
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});
    }
    
    
    function getRuntimeInformation() {
    	var grid, store, dataStore;
    	
    	dojo.xhrGet({
			url: bookingsPath.concat(basePath.concat("config/runtime")),
			handleAs: "json",
			load: function(response, ioArgs) {
				var theData = { items : response };
				var tableData = '';
			 
					tableData += '<table border="1">';
					tableData += '<tr>';
					tableData += '   <th>Name</th>';
					tableData += '   <th>Description</th>';
					tableData += '</tr>';
					var itemLength = theData.items.length;
				    for (var i = 0; i < itemLength; i++){
						tableData += '<tr>';
						tableData += '   <td>'+theData.items[i].name+'</td>';
						tableData += '   <td>'+theData.items[i].description+'</td>';		
						tableData += '</tr>';
				    }
					tableData += '</table>';
				
    			document.getElementById('runtimeLoc').innerHTML=tableData;
				return false;				
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});
    }    
    
    
    
    function getActiveDataServiceInfo() {
    	var grid, store, dataStore;
    	
    	dojo.xhrGet({
			url: bookingsPath.concat(basePath.concat("config/activeDataService")),
			handleAs: "text",
			load: function(response, ioArgs) {	
		    	document.getElementById('activeServiceLoc').innerHTML="The active Data Service is '".concat(response).concat("''");		    	
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});
    }    
    
    
    function getDBSizes() {
    	var grid, store, dataStore;
    	var airportCodeMapping, booking, customer, customerSession, flight, flightSegment;

    	dojo.xhrGet({
			url: customersPath.concat(basePath.concat("config/countCustomers")),
			handleAs: "json",
			load: function(response, ioArgs) {
		    	document.getElementById('custData').innerHTML=response;
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});
    		
    	dojo.xhrGet({
			url: customersPath.concat(basePath.concat("config/countSessions")),
			handleAs: "json",
			load: function(response, ioArgs) {			    	
		    	document.getElementById('sessionData').innerHTML=response;
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});
    	
       	dojo.xhrGet({
			url: bookingsPath.concat(basePath.concat("config/countFlights")),
			handleAs: "json",
			load: function(response, ioArgs) {
		    	document.getElementById('flightData').innerHTML=response;
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});
	 
       	dojo.xhrGet({
			url: bookingsPath.concat(basePath.concat("config/countFlightSegments")),
			handleAs: "json",
			load: function(response, ioArgs) {
		    	document.getElementById('flightSegmentData').innerHTML=response;
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});      
       	
       	
    	dojo.xhrGet({
			url: bookingsPath.concat(basePath.concat("config/countBookings")),
			handleAs: "json",
			load: function(response, ioArgs) {
		    	document.getElementById('bookingData').innerHTML=response;
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});	
    	
    	dojo.xhrGet({
			url: bookingsPath.concat(basePath.concat("config/countAirports")),
			handleAs: "json",
			load: function(response, ioArgs) {	
		    	document.getElementById('airportData').innerHTML=response;
			},
			error: function(response, ioArgs) {
				alert(response);
			}
    	});	
    	
		return false;
    } 
    
	function formatFlightNumnber(data) {
		return data.name[0];
	}
  </script>
</head>

<body class="claro">

<span id="variousDialogs" style="display:none">
<div dojoType="dijit.Dialog" id="loginWaitDialog" title="Please Wait">
		<table width="258">
			<tr><td>Logging in ...</td></tr>
		</table>
</div>

<div dojoType="dijit.Dialog" id="loginDialog" title="Login">
		<table width="258">
			<tr>
				<td><label>Login</label></td>
				<td><input type="text" trim="true" dojoType="dijit.form.TextBox" value="uid0@email.com" name="login" id="userId"/></td>
			</tr>
			<tr>
				<td><label>Password</label></td>
				<td><input type="password" trim="true" dojoType="dijit.form.TextBox" value="password" name="password" id="password"/></td>
			</tr>
			<tr>
				<td colspan="2">&nbsp;</td>
			</tr>
			<tr>
				<td colspan="2" align="center">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<tr>
							<td  align="center" valign="top" width="40%"><button dojoType="dijit.form.Button" id="LoginButton" onClick="login()">Ok</button></td>
							<td align="left" valign="top" width="3%">&nbsp;</td>
							<td align="left" valign="top" width="57%"><button dojoType="dijit.form.Button" onclick="hideLoginDialog()" id="Cancel">Cancel</button></td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
</div>


<div dojoType="dijit.Dialog" id="waitDialog" title="Please Wait">
		<table width="258">
			<tr><td>Please Wait...</td></tr>
		</table>
		
</div>
</span>
    
<div id="main">
	<br/>
	<header>
		<br/><br/><br/>
		<img src="images/Huawei Air.png" alt="Huawei Air"/><br/><br/>
		<div class="text-align: left">Our commitment, your pursuit.</div><br/>
	</header>
	<div id="welcomeback"><div id="loggedinwelcome"></div>
	</div>
	<div id="main_content">
		<span data-dojo-type="dijit.Declaration" data-dojo-props='widgetClass:"ToolbarSectionStart", defaults:{ label: "Label"}'>
			<span data-dojo-type="dijit.ToolbarSeparator"></span><i>${label}:</i>
		</span>

		<div id="toolbar5" data-dojo-type="dijit.Toolbar">
			<div data-dojo-type="ToolbarSectionStart" data-dojo-props='label:"Actions"'></div>
			<div id="toolbar5.home" data-dojo-type="dijit.form.Button" data-dojo-props='showLabel:true' onClick="window.location='index.html'">Huawei Air Home</div>
			<div id="toolbar5.loaddb" data-dojo-type="dijit.form.Button" data-dojo-props='showLabel:true' onClick="window.location='loader.html'">Load the Database</div>
			<div id="toolbar5.info" data-dojo-type="dijit.form.Button" data-dojo-props='showLabel:true' onClick="window.location='config.html'">Runtime Info</div>
		</div>
		
		<div class="content">
			<h1 style="margin: 15px 0 0 0;">Huawei Air Configuration Information</h1>
			
			<h2>Application Runtime</h2>
			
			<script type="text/javascript">
				getRuntimeInformation();
			</script>
			<div id="runtimeLoc"></div>	
			
			<h2>Available Data Services </h2>
			
			<script type="text/javascript">
				getDataServiceInformation();
				getActiveDataServiceInfo();
			</script> 
			<div id="targetLoc"></div><br/>
			<div id="activeServiceLoc"></div>
			<br/>
			<script type="text/javascript">
				getDBSizes();
			</script> 
			
		  <h2> Database Information </h2>
          <table border="1">
		     <tr> <th>Entity</th> <th>Count</th></tr>
		     <tr> <td>Bookings</td> <td><div id="bookingData"></div></td></tr>
	         <tr> <td>Customers</td> <td><div id="custData"></div></td></tr>
	         <tr> <td>Sessions</td> <td><div id="sessionData"></div></td></tr>
	         <tr> <td>Flights</td> <td><div id="flightData"></div></td></tr>
	         <tr> <td>Flight Segments</td> <td><div id="flightSegmentData"></div></td></tr>
	         <tr> <td>Airports</td> <td><div id="airportData"></div></td></tr>
          </table>
			
						
		</div>
	</div>
	<footer>
		<p><a href="index.html">Huawei Air Home</a></p>
	</footer>

</div>

</body>
</html>
